home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 15.0 KB | 445 lines | [TEXT/MPS ] |
- // UTECommands.h
- // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __UTECOMMANDS__
- #define __UTECOMMANDS__
-
- // MacApp
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- // Toolbox
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TEditText;
- class TTEView;
-
-
- //----------------------------------------------------------------------------------------
- // TTECommand: A command that adds characters to, or delete characters from, a TEView
- //----------------------------------------------------------------------------------------
-
- class TTECommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TTEView* fTEView; // The TEView operated on
-
- TEditText* fEditText; // The TEditText operated on. This command
- // class can be used to modify either TTEView
- // or TEditText.
-
- TEHandle fHTE; // same as fTEView's fHTE; duplicated for
- // code efficiency
-
- short fOldStart; // The beginning position of the selection
- // at the moment just before the command
- // was done.
-
- short fOldEnd; // The end position of the selection at
- // the moment just before the command was
- // done.
-
- Handle fOldText; // If fOldStart = fOldEnd, i.e., if old
- // selection had been an insertion CPoint,
- // this will be NULL. Otherwise, provides a
- // temporary home for the characters
- // comprising the old selection
-
- CStr255 fOldStaticText; // Temporary home for TStaticText contents.
- // Note: TEditText derives from TStaticText
-
- StScrpHandle fOldStyles;
-
- short fNewStart; // The beginning location in the Text of
- // the new text that is added by the
- // command, if any.
-
- short fNewEnd; // The ending location in the Text of the
- // new text that is added by the command,
- // if any.
-
- Handle fNewText; // A Handle to the characters added by the
- // command
-
- StScrpHandle fNewStyles;
-
- Handle fPadding; // Handle to fill size between new and
- // old. This insures that we can always
- // undo and redo.
-
- short fTextPad; // Size difference between New and Old
- // text
-
- long fStylePad; // Size difference between New and Old
- // styles
-
-
- //------------------------------------------------------------------------------------
- // Initialize and Free
- //------------------------------------------------------------------------------------
-
- TTECommand();
- // Constructor
-
- void ITECommand(TTEView* itsTEView, CommandNumber itsCommandNumber, Boolean itsSaveText);
- // Initialize the command; if unsuccessful, exit is via Failure mechanism.
-
- void ITECommand(TEditText* itsEditText, CommandNumber itsCommandNumber, Boolean itsSaveText);
- // Overload initializer to work with TEditText views.
-
- virtual ~TTECommand();
- // Free the text handles holding information needed for Undo/ Redo, then Inherited::Free.
-
-
- //------------------------------------------------------------------------------------
- // Command execution phase overrides
- //------------------------------------------------------------------------------------
-
- virtual void DoIt();
- // Focuses, then calls DoMainFunction
-
- virtual void RedoIt();
- // Focuses, calls RestoreSelection to get selection right, then calls
- // DoMainFunction to reinstate the changes done in DoIt which were undone by a
- // preceding UndoIt
-
- virtual void UndoIt();
- // Focuses, then dispatches to RemoveAdditions, ReviveDeletions, and
- // RestoreSelection to accomplish the Undo
-
- virtual void SetupDependencies(); // Override
- // Overridden to make this command a dependent of its fTEView.
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace); // Override
- // If the fTEView is closed, commit this command
-
- //----------------------------------------------------------------------------------------
- // Command execution - Restoration of Selection -- called in both UNDO and REDO phases
- //----------------------------------------------------------------------------------------
-
- virtual void RestoreSelection();
- // Set the Selection to be what it was just before the DO phase of the command was
- // performed
-
- virtual void PrepareForUndoRedo(); // override
- // Make the command context visible for undo/redo.
-
- virtual void RevealUndoRedo(); // override
- // Make this context visible after undo/redo.
-
-
- //------------------------------------------------------------------------------------
- // Command execution - steps in DO and REDO phases
- //------------------------------------------------------------------------------------
-
- virtual void AssureTEView();
- // Guarantee that a TEView exists when the command knows about a TEditText.
-
- virtual void ForgetTEView();
- // Forget references to the TEView when the command knows about a TEditText.
-
- virtual void DoPostProcess();
- // Put TEView/TEdit text fields in post-process state.
-
- virtual void BanishOldText();
- // Remove text that was selected at the outset of the Do phase
-
- virtual void InstallNewText();
- // Install the new text
-
- virtual void DoMainFunction();
- // Forwards to the relevant methods for Do and Redo phases
-
-
- //------------------------------------------------------------------------------------
- // Command execution - steps in UNDO phase
- //------------------------------------------------------------------------------------
-
- virtual void RemoveAdditions();
- // Remove any characters which were added by the DO phase of the command
-
- virtual void ReviveDeletions();
- // Bring back the characters which were removed during the DO phase
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TTECutCopyCommand: Command for handling Cut & Copy for the TEView.
- //----------------------------------------------------------------------------------------
-
- class TTECutCopyCommand : public TTECommand
- {
- MA_DECLARE_CLASS;
-
- public:
- Boolean fClipCreated; // Clipboard view created OK
-
-
- //------------------------------------------------------------------------------------
- // Creation and Destruction
- //------------------------------------------------------------------------------------
-
- TTECutCopyCommand();
- // Empty constructor to satisfy compiler.
-
- void ITECutCopyCommand(TTEView* itsTEView, CommandNumber itsCommandNumber);
-
- // Initializes the command
-
- virtual ~TTECutCopyCommand();
- // Free the command
-
-
- //------------------------------------------------------------------------------------
- // Command execution
- //------------------------------------------------------------------------------------
-
- virtual void DoIt();
- // Launches a TEView for installation in the Clipboard, then calls DoMainFunction
- //
-
- virtual void ReviveDeletions();
- // Bring back the characters which were removed during the DO phase; called during
- // UNDO phase
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TTEPasteCommand: Command that handles Pasting for the TEView.
- //----------------------------------------------------------------------------------------
-
- class TTEPasteCommand : public TTECommand
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialization
- //------------------------------------------------------------------------------------
-
- TTEPasteCommand();
- // Empty constructor to satisfy compiler.
- virtual ~TTEPasteCommand();
- // Destructor
-
- void ITEPasteCommand(TTEView* itsTEView);
- // Initialize the command; if unsuccessful, signalled by Failure mechanism
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TTEStyleCommand: Command for applying a new style to the TEView.
- //----------------------------------------------------------------------------------------
-
- class TTEStyleCommand : public TTECommand
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // These two fields are only used in non-styled TextEdit records
- //------------------------------------------------------------------------------------
-
- short fMode; // Mode for style change
-
- TextStyle fOldTextStyle; // The original text style
-
- TextStyle fNewTextStyle; // What we're replacing it with
-
-
- //------------------------------------------------------------------------------------
- // Initialization
- //------------------------------------------------------------------------------------
-
- TTEStyleCommand();
- // Empty constructor to satisfy compiler.
- virtual ~TTEStyleCommand();
- // Destructor
-
- void ITEStyleCommand(TTEView* itsTEView,
- const TextStyle& itsNewStyle,
- CommandNumber itsCommandNumber,
- short itsMode);
- // Initialize the command; if unsuccessful, signalled by Failure mechanism
-
-
- //------------------------------------------------------------------------------------
- // Command execution
- //------------------------------------------------------------------------------------
-
- virtual void InstallOneStyle(const TextStyle& newStyl);
- // Installs one style over entire record - for use with old TextEdit
-
- virtual void InstallManyStyles(StScrpHandle newStyls);
- // Installs styles over selection range - for use with styled TextEdit
-
- virtual void DoIt();
- // Applies style to selection range
-
- virtual void UndoIt();
- // Undoes the action performed by DoIt.
-
- virtual void RedoIt();
- // Calls DoIt.
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TTETypingCommand: The command that handles typing in a TEView.
- //----------------------------------------------------------------------------------------
-
- class TTETypingCommand : public TTECommand
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Creation and destruction
- //------------------------------------------------------------------------------------
-
- TTETypingCommand();
- // Empty constructor to satisfy compiler.
-
- void ITETypingCommand(TTEView* itsTEView, const CStr2& itsFirstCh);
- // Initialize the command; if not successful, exit is via Failure mechanism
-
- virtual ~TTETypingCommand();
- // Deallocate the command and dependent structures
-
-
- //------------------------------------------------------------------------------------
- // Command processing
- //------------------------------------------------------------------------------------
-
- virtual void DoNormalChar(const CStr2& ch);
- // Handle any typed character[s] except a backspace
-
- virtual void BkSpcLeft(Handle theText, short curStart);
- // Handle backspace to the left of the original selection
-
- virtual void BkSpcRight(Handle theText, short curStart);
- // Handle backspace to the right of the original selection
-
- virtual void FwdDelete(Handle theText, short curStart, short curEnd);
-
-
- //------------------------------------------------------------------------------------
- // Handle forward delete
- //------------------------------------------------------------------------------------
-
- virtual void AddCharacter(const CStr2& ch);
- // Add character[s] to an already-launched TETypingCommand
-
- virtual void DoIt();
- // First processing for command; adds first character
-
- virtual void RedoIt();
- // Handles undoing forward backspace
-
- virtual void UndoIt();
- // Process undo typing
-
- virtual void CompleteTyping();
- // Mark as no more typing allowed and fix up style scrap, if any
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- Boolean fCompleted; // Indicates whether further keystrokes
- // will be extensions to this command
- // (false) or whether the command has
- // already been completed (true)
-
- CStr2 fFirstChar; // First character[s] typed
- };
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TTEDragDropCommand: Command that handles a drag or drop text operation.
- //----------------------------------------------------------------------------------------
-
- class TTEDragDropCommand : public TTECommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TTEDragDropCommand();
- // default constructor
- virtual ~TTEDragDropCommand();
- // Destructor
-
- void ITEDragDropCommand(TTEView *itsTEView, CommandNumber itsCommandNumber); // overloaded initializer
-
- void ITEDragDropCommand(TEditText *itsEditText, CommandNumber itsCommandNumber);
-
- void DoMainFunction();
- // Override. Don't banish the old text.
-
- virtual void SetNewText(Handle newText, StScrpHandle newStyles);
- // set text to be installed in the target TTEView
-
- virtual void SetNewStart(short newStart);
- // set the location for the new text
-
- virtual void InstallNewText();
- // OVERRIDE
-
- }; // class TTEDragDropCommand
-
- //----------------------------------------------------------------------------------------
- // TTEDragMoveCommand: Command that handles moving text within a view as a result of
- // a drag
- //----------------------------------------------------------------------------------------
-
- class TTEDragMoveCommand : public TTECommand
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TTEDragMoveCommand();
- // Constructor
-
- void ITEDragMoveCommand(TTEView *itsTEView, CommandNumber itsCommandNumber, short newStart);
-
- void ITEDragMoveCommand(TEditText *itsEditText, CommandNumber itsCommandNumber, short newStart);
-
- virtual ~TTEDragMoveCommand();
-
- virtual void InstallNewText();
- };
-
- #endif // qDrag
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
- void DumpTTECommand(TTECommand* theTTECommand);
- // writes TTECommand info out to Debug window
-
- #endif
-
-